import random
import string

import numpy as np
import matplotlib.pyplot as plt

# We define two sequences x, y as numpy array
# where y is actually a sub-sequence from x
x = np.array([2, 0, 1, 1, 2, 4, 2, 1, 2, 0]).reshape(-1, 1)
y = np.array([1, 1, 2, 4, 2, 1, 2, 0]).reshape(-1, 1)

from dtw import dtw

euclidean_norm = lambda x, y: np.abs(x - y)

dist, cost_matrix, acc_cost_matrix, path = dtw(x, y, dist=euclidean_norm)

print(dist, path, '\n', acc_cost_matrix)

colors = random.Random()

plt.plot(x)
plt.plot(y)
for i in range(len(path[0])):
    color = '#'+''.join(colors.sample(string.hexdigits, 6))
    plt.scatter(path[0][i], x[path[0][i]][0], c=color)
    plt.scatter(path[1][i], y[path[1][i]][0], c=color)
plt.show()

